import { createApp } from 'vue';
import './style.css';
import store from '@/stores';
import router from '@/router';
import { createPinia } from 'pinia';
import App from './App.vue';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'element-plus/dist/index.css';

import VMdEditor from '@kangc/v-md-editor';
import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import '@kangc/v-md-editor/lib/theme/style/github.css';

import '@/assets/styles/main.css';

import { appPermission } from './composables/useAppPermission';
import { PermissionComponent } from './composables/usePermission';

VMdEditor.use(githubTheme);

// 初始化权限
appPermission.initPermissionMap();
// 设置用户信息
appPermission.setUser({
  id: 1,
  name: '管理员',
  role: 'admin',
  permissions: ['special:permission']
});
// 创建vue实例
const app = createApp(App);

// 注册全局指令
app.directive('permission', appPermission.vPermission);

// 注册全局组件
app.component('PermissionComponent', PermissionComponent);

// 挂载pinia
app.use(store)
  .use(router)
  .use(createPinia())
// 注册图标组件
  .use(VMdEditor);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
// 挂载实例
app.mount('#app');

